const mysql = require('mysql2/promise');
const ApiResult = require('../utils/apiResult');

const express = require('express');
const router = express.Router();

const pool = mysql.createPool({
    host: '127.0.0.1',
    port: 43386,
    user: 'root',
    password: '5AgJXpCVxtzK',
    database: 'rustservice',
    waitForConnections: true,
    connectionLimit: 10,
    maxIdle: 10, // 最大空闲连接数，默认等于 `connectionLimit`
    idleTimeout: 60000, // 空闲连接超时，以毫秒为单位，默认值为 60000 ms
    queueLimit: 0,
    enableKeepAlive: true,
    keepAliveInitialDelay: 0,
  });
router.get('/mysql',async (req,rep)=>{
    
    //let arr = [];
    try{
        const [results,fields] = await pool.query('select * from sys_logs');
        rep.json(ApiResult.success(results))
    }catch(e){
        console.log(e);
        rep.json(ApiResult.error());
    }
})

module.exports = router;